package com.hxl.demo.service.Impl;

import com.hxl.demo.entity.Staff;
import com.hxl.demo.entity.TrainingRecord;
import com.hxl.demo.mapper.StaffMapper;
import com.hxl.demo.mapper.TrainingRecordMapper;
import com.hxl.demo.service.TrainingRecodeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class TrainingRecodeServiceImpl implements TrainingRecodeService {
    @Resource
    private TrainingRecordMapper trainingRecordMapper;
    @Resource
    private StaffMapper staffMapper;

    @Override
  public  Integer beginStudy(Integer userId, Integer contentId, Date beginTime){
        List<Staff> staffList=staffMapper.getStaffList(null,null,"","","","","",userId);
            Integer deptId=null;
        if(staffList!=null && staffList.size()>0){
            deptId=staffList.get(0).getDeptId();
        }

      return trainingRecordMapper.beginStudy(userId,contentId,beginTime,new Date(),deptId);
  }


    @Override
    public  List<Map<String,Object>> getRecodeById(Integer userId, Integer contentId){
     return trainingRecordMapper.getRecodeById(userId, contentId);
    }

    @Override
    public List<Map<String, Object>> getRecodeByCount(Integer userId, Integer contentId) {
        return trainingRecordMapper.getRecodeByCount(userId, contentId);
    }

    @Override
    public Integer endStudy(Integer id, Date endTime, Integer trainingTime, Integer cumulativeTime) {
        return trainingRecordMapper.endStudy(id, endTime,trainingTime,cumulativeTime);
    }

}
